library TriggerUtils initializer onInit requires Table
    globals
        private Table tab
    endglobals

    function SetTriggerData takes trigger tr, integer data returns trigger
        set tab[GetHandleId(tr)] = data
        return tr
    endfunction

    function GetTriggerData takes trigger tr returns integer
        return tab[GetHandleId(tr)]
    endfunction

    function NewTrigger takes nothing returns trigger
        return CreateTrigger()
    endfunction

    function NewTriggerEx takes integer data returns trigger
        local trigger tr = NewTrigger()
        call SetTriggerData(tr, data)
        return tr
    endfunction

    function ReleaseTrigger takes trigger tr returns integer
        local integer data = 0

        if tr != null then
            set data = GetTriggerData(tr)
            call tab.remove(GetHandleId(tr))
            call DestroyTrigger(tr)
        endif
        
        return data
    endfunction

    function TriggerRegisterAllPlayerEvent takes trigger tr, playerunitevent whichevent, code condition returns nothing
        local integer i
        set i = 0
        loop
            exitwhen i >= bj_MAX_PLAYER_SLOTS
            call TriggerRegisterPlayerUnitEvent(tr, Player(i), whichevent, null)
            set i = i + 1
        endloop
        call TriggerAddCondition(tr, Condition(condition))
    endfunction

    private function onInit takes nothing returns nothing
        set tab = Table.create()
    endfunction
endlibrary
